<div class="modal fade " id="uploadReportDataSourceModal"  role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">数据文件上传</h3>
            </div>

            <!-- form start -->
            <form class="form-horizontal" role="form" id="uploadReportDataSourceForm"  method="post" action="/reportdatasource/uploadreportdatasourcefile" enctype="multipart/form-data">
                <div id="toolbar">
                    <div class="form-group">
                        <input id="datasourceType" name="datasourceType" type="text" style="display:none;">
                        <label class="col-sm-2 control-label" for="datasourceLable">类型</label>
                        <div class="col-sm-5">
                            <select id="datasourceList" name="datasourceList" class="form-control">
                                <option value="2">数据文件</option>
                                <option value="3">数据库表文件</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <input id="paramValue" name="paramValue" type="text" style="display:none;">
                        <label class="col-sm-2 control-label" for="remarkLabel">备注</label>
                        <div class="col-sm-5">
                            <input id="remark" name="remark" type="text" class="form-control">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="inputFileLabel">数据文件</label>
                        <div class="col-sm-5">
                            <input type="file" id="file" name="file">
                        </div>
                    </div>
                </div>
                <div class="box-footer">
                    <button type="button" class="btn btn-danger pull-left" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary pull-right" onclick="uploadReportDataSourceFile()">上传</button>
                </div>
            </form>
        </div>
    </div>
</div>
<#include "../public/js.ftl" >
<#include "../public/css.ftl">
<script>
    function uploadReportDataSourceInit() {
        //初始化页面，设置各组件默认值
        $("#remark").val("");
        $("#file").val("");
        $("#datasourceList").val("2");
    }

    function uploadReportDataSourceFile() {

        //检查数据文件类型
        var datasourceList = document.getElementById("datasourceList");
        var index = datasourceList.selectedIndex;
        $("#datasourceType").val(datasourceList.options[index].value);
        var datasourceType = $("#datasourceType").val();

        //检查类型是否为数据文件或数据库表文件
        if(datasourceType != "2" && datasourceType != "3") {
            toastr['error']("请选择类型",'异常');
            return;
        }

        var filename = $("#file").val();

        if (filename == null || filename == undefined || filename == "" || filename.trim() == "") {
            toastr['error']("未选择上传文件", '异常');
            return;
        }

        var remark = $("#remark").val();

        //上传文件
		var data = {
		    datasourceType : datasourceType,
		    remark : remark
		};

		fileReq("/reportdatasource/uploadreportdatasourcefile","file",data,function(result){
			if(result.success) {
				toastr['success']('文件上传成功', '提示');
				uploadReportDataSourceInit();
				$("#uploadReportDataSourceModal").modal("hide");
				$("#dataSourceTable").bootstrapTable("refresh");
			} else {
				toastr['error'](result.msg, '提示');
			}
		});
    }
</script>
